package com.qiyadeng.thread;

public class MyWaitNotify {
	MonitorObject myMonitorObject = new MonitorObject();
	boolean signal = false;
	  public void doWait(){
	    synchronized(myMonitorObject){
	      System.out.println("enter do wait");
	    	while (!signal){
	      try{
	    	  System.out.println("wait now");
	        myMonitorObject.wait();
	        
	        Thread.sleep(4000);
	      } catch(InterruptedException e){}
	    	System.out.println("exit do wait");
	    }
	    	signal = false;
	    }
	  }

	  public void doNotify(){
		  
	    synchronized(myMonitorObject){
	    	System.out.println("enter do notify");
	    	System.out.println("before notify");
	    	if(signal){
	    		signal = true;
	    	myMonitorObject.notify();
	    	try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
	    	System.out.println("exit do notify");
	    	}
	    }
	  }
}
